package com.study.spring.netty.time_client;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;

import java.nio.charset.StandardCharsets;
import java.util.List;

public class TimeClientDecode extends ByteToMessageDecoder {

    @Override
    protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
        int count = in.readableBytes();
        if (count >= 17) {
            byte[] bytes = new byte[17];
            in.readBytes(bytes);
            out.add(new String(bytes, StandardCharsets.UTF_8));
        }
    }
}
